
function copyCode(obj)
{
	var rng = document.body.createTextRange();
	rng.moveToElementText(obj);
	rng.select();
	rng.execCommand("Copy");
}

function saveCode(obj, filename)
{
	var winname = window.open('', '_blank', 'top=10000');
	winname.document.open('text/html', 'replace');
	winname.document.writeln(obj.value);
	winname.document.execCommand('saveas','', filename);
	winname.close();
}

function toHTML(s)
{
	s = s.split("&").join("&amp;");
	s = s.split("<").join("&lt;");
	return s.split(">").join("&gt;");
}

function Redirect(url)
{
	window.location = url;
}

// function compress(str)
// {
// 	newStr = "";
// 	for (i = 0, c = 0; i < str.length; ++i)
// 	{

// 	}
// }


function strToHex(str)
{
	var hexArr = "0123456789abcdef"; 
	var newStr = "";
	for (var i = 0; i < str.length; ++i)
	{
		code = str.charCodeAt(i);
		a = code & (0x000f);code >>= 4;
		b = code & (0x000f);code >>= 4;
		c = code & (0x000f);code >>= 4;
		d = code & (0x000f);
		newStr += hexArr[d];
		newStr += hexArr[c];
		newStr += hexArr[b];
		newStr += hexArr[a];
	}
	return newStr;
}

function hexToStr(hexStr)
{
	var numArr = {"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"a":10,"b":11,"c":12,"d":13,"e":14,"f":15};
	var newStr = "";
	for (var i = 0; i < hexStr.length; i += 4)
	{
		d = numArr[hexStr[i]];
		c = numArr[hexStr[i + 1]];
		b = numArr[hexStr[i + 2]];
		a = numArr[hexStr[i + 3]];
		code = ((d << 12) | (c << 8) | (b << 4) | a);
		newStr += String.fromCharCode(code);
	}
	return newStr;
}

function codeToHtml(str)
{
	str = str.replace(/[<>&"]/g,function(c){return {'<':'&lt;','>':'&gt;','&':'&amp;','"':'&quot;'}[c];});
	str = str.replace(/\x20/g, "&nbsp;");
	str = str.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
	str = str.replace(/\r\n/g, "<br />");
	str = str.replace(/\n/g, "<br />");
	return str;
}

function htmlToCode(str)
{
	str = str.replace(/&nbsp;/g," ");
	str = str.replace(/&lt;/g,"<");
	str = str.replace(/&gt;/g,">");
	str = str.replace(/&quot;/g,"\"");
	str = str.replace(/&amp;/g,"&");
	str = str.replace(/<br \/>/g,"\r\n");
	return str;
}